#ifndef _ELOG_FILE_IO_H_
#define _ELOG_FILE_IO_H_

#include "lfs.h"                   /* include lfs.h for littlefs */
#include "stdio.h"
#include "string.h"

extern lfs_t lfs;

#define ELOG_FILETYPE    lfs_file_t
#define elog_openread(filename, file)   (lfs_file_open(&lfs, (file), (filename), LFS_O_RDONLY | LFS_O_CREAT) == LFS_ERR_OK)
#define elog_openwrite(filename, file)  (lfs_file_open(&lfs, (file), (filename), LFS_O_WRONLY | LFS_O_CREAT) == LFS_ERR_OK)
#define elog_openappend(filename, file)  (lfs_file_open(&lfs, (file), (filename), LFS_O_RDWR | LFS_O_CREAT | LFS_O_APPEND))
#define elog_close(file)               (lfs_file_close(&lfs, file) == LFS_ERR_OK)
#define elog_read(buffer, size, file)    (ini_lfs_gets((buffer), (size), (file)))
#define elog_write(buffer, size, file)        (lfs_file_write(&lfs, (file), (buffer), size))
#define elog_remove(filename)          (lfs_remove(&lfs, filename) == LFS_ERR_OK)
#define elog_rename(source, dest)         (lfs_rename(&lfs, (source), (dest)) == LFS_ERR_OK)
#define elog_filesize(file, filesize)    (*(filesize) = lfs_file_size(&lfs, (file)))

#define ELOG_FILEPOS                   lfs_soff_t
#define elog_tell(file, pos)            (*(pos) = lfs_file_tell(&lfs, (file)))
#define elog_seek(file, pos)            (lfs_file_seek(&lfs, (file), *(pos), LFS_SEEK_SET) == LFS_ERR_OK)

#endif /* _ELOG_FILE_PORT_H_ */